/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-08
 * Time: 17:58
 */
// 单例模式(懒汉模式)SingletonLazy

class SingletonLazy{
    private static volatile SingletonLazy  instance;

    public static SingletonLazy getInstance() {
        // instance 如果为 null, 说明是首次调用, 就需要加锁. 如果非 null, 就说明是后续调用, 就不用加锁了.
        if (instance == null) {
            synchronized (SingletonLazy.class) {
                if (instance == null) {
                    return instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }
    private SingletonLazy() {};
}
public class test_1 {
    // 单例模式(懒汉模式)SingletonLazy

    public static void main(String[] args) {

    }
}
